package com.ml.admin.utils;

import com.fasterxml.jackson.annotation.JsonInclude;
import lombok.Builder;
import lombok.Data;

import java.io.Serializable;

/**
 * @author ml
 * @date 2023/2/24 13:57
 */

@Data
@Builder
@JsonInclude(JsonInclude.Include.NON_NULL)
public class ReturnResponse<T> implements Serializable {

    private static final long serialVersionUID = 1L;

    private String resCode;
    private String resMsg;
    private T data;

    public static ReturnResponse<Object> success() {
        ReturnResponse<Object> build = ReturnResponse.builder().resCode(ResponseEnum.SUCCESS.getCode()).resMsg(ResponseEnum.SUCCESS.getMessage()).build();
        return build;
    }

    public static ReturnResponse<Object> failure() {
        ReturnResponse<Object> build = ReturnResponse.builder().resCode(ResponseEnum.FAILURE.getCode()).resMsg(ResponseEnum.FAILURE.getMessage()).build();
        return build;
    }

    public static ReturnResponse<Object> success(Object data) {
        ReturnResponse<Object> build = ReturnResponse.builder()
                .resCode(ResponseEnum.SUCCESS.getCode()).resMsg(ResponseEnum.SUCCESS.getMessage()).data(data).build();
        return build;
    }

    public static ReturnResponse<Object> failure(Object data) {
        ReturnResponse<Object> build = ReturnResponse.builder()
                .resCode(ResponseEnum.FAILURE.getCode()).resMsg(ResponseEnum.FAILURE.getMessage()).data(data).build();
        return build;
    }
    public static ReturnResponse<Object> failure(ResponseEnum responseEnum) {
        ReturnResponse<Object> build = ReturnResponse.builder()
                .resCode(responseEnum.getCode()).resMsg(responseEnum.getMessage()).build();
        return build;
    }


}